﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Portal.Web.Global;
using Portal.Db.Service;
using Portal.Core;
using Portal.Utilities;
using Portal.Web.Framework;
using Portal.AssetTn.Model;
using Portal.Ws.Utilities.Ws;
using Portal.Ws.Utilities;
using System.IO;

namespace Portal.Gui.Web.WebParts.AssetTn
{
    public class AssetMaterialBll
    {
        public AssetMaterialCls[] ReadingAssetMaterial(string SiteId, string Keyword)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "ReadingAssetMaterial");
            oWsInParam.Keyword=Keyword;
            WsOutParam outParam = UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
            AssetMaterialCls[] AssetMaterial = AssetMaterialParser.ParseMultiRecordFromXml(outParam.XmlData);
            if (AssetMaterial == null) AssetMaterial = new AssetMaterialCls[0];
            return AssetMaterial;
        }



        public AssetMaterialCls CreateAssetMaterialModel(string SiteId, string AssetMaterialId)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "CreateAssetMaterialModel");
            oWsInParam.KeyId = AssetMaterialId;
            WsOutParam outParam = UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
            AssetMaterialCls OAssetMaterial = AssetMaterialParser.ParseFromXml(outParam.XmlData);
            return OAssetMaterial;
        }


        public void SaveAssetMaterial(string SiteId, string AssetMaterialId, AssetMaterialCls OAssetMaterial)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "SaveAssetMaterial");
            oWsInParam.KeyId = AssetMaterialId;
            oWsInParam.XmlData = AssetMaterialParser.GetXml(OAssetMaterial);
            UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
        }


        public void AddAssetMaterial(string SiteId, AssetMaterialCls OAssetMaterial)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "AddAssetMaterial");
            oWsInParam.XmlData = AssetMaterialParser.GetXml(OAssetMaterial);
            UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
        }


        public void DeleteAssetMaterial(string SiteId, string AssetMaterialId)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "DeleteAssetMaterial");
            oWsInParam.KeyId = AssetMaterialId;
            UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
        }
    }
}
